<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>自动聚焦</title>
</head>

<body>
  <div id="app">
    <!-- 使用自定义指令 -->
    <input type="text" v-focus>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    Vue.directive('focus', {
      inserted: function (el) {
        el.focus()
      }
    })
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>

</html>